> So again I'm back to the quesiton, "How to 'declare' a string variable?"
I don't know if this will help answer the question, which I am admittedly quite confused about. However, a few smart tests can take you far. Try this:
procedure main()
s1 := "This is a string"
write(s1)
# s2[2] := s1
# write(s2)
s3 := "Oh, no, Mr. Bill! "
s4 := s3 || s1
write(s4)
s3[2] := s1
write(s3)
exit()
end
You get:
This is a string
Oh, no, Mr. Bill! This is a string
OThis is a string, no, Mr. Bill!
Now remove the comments and watch it die. Why? I'm not a guru on the innards of Icon parsing, but my guess is that the line
s2[2] := s1
is ambiguous. s2 could be a string OR a table. Either one would be syntactically correct. So what's a parser to do? Later on, s3 is already a string, so there is no question. So, to "declare" a string s, first use it as a string. s := "" should be sufficient. Modify the program again:
procedure main()
s1 := "This is a string"
write(s1)
# s2[2] := s1
# write(s2)
s3 := "Oh, no, Mr. Bill! "
s4 := s3 || s1
write(s4)
s3[2] := s1
write(s3)
s5 := "" # new
s5 := s1 # new
write(s5) # new
exit()
end
you get
This is a string
Oh, no, Mr. Bill! This is a string
OThis is a string, no, Mr. Bill!
This is a string
Does this help? If not, copy it and continue working with it.